<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聚造-登录</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>

<body>
    <div id="app">
        <switch-button></switch-button>
        <switch-button></switch-button>
        <switch-button></switch-button>
        <switch-button></switch-button>
    </div>
</body>
<div id="app">
    <switch-button></switch-button>
    <switch-button></switch-button>
    <switch-button></switch-button>
    <switch-button></switch-button>
</div>
<script type="text/javascript">
    //注册Vue 全局组件
    Vue.component('switch-button', {
        template: '<div v-if="close" v-on:click="show(1)" style="width: 120px;height: 36px;background: dimgrey;border-radius: 18px;margin-top: 10px;"><div style="width:36px;height: 36px;border-radius: 18px;background: white;"></div></div><div   v-on:click="show(2)" v-else style="width: 120px;height: 36px;background: green;border-radius: 18px;margin-top: 10px;"><div style="width:36px;height: 36px;border-radius: 18px;background: white;margin-left: 85px;"></div>',
        data: function () { 
            return {
                close: true
            }
        },
        methods: {
            show: function (num) {
                if (num == 1) {
                    this.close = false;
                } else {
                    this.close = true;
                }
            }
        }
    })
    new Vue({
        el: '#app',
    });
</script>

</html>